﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Moving03.Administrator
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        DataClasses1DataContext context = new DataClasses1DataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated == false || User.Identity.IsAuthenticated == true && !User.IsInRole("Admin"))
            {
                Response.Redirect("../Default.aspx");
            }
            loadLoHangCach1();

        }

        private void loadLoHangCach1()
        {
            string s = "";
            var query = from ttvc in context.ThongTinVanChuyens
                        join lh in context.LoHangs on ttvc.Id_LoHang equals lh.Id_LoHang
                        join tt in context.TinhTrangVanChuyens on ttvc.TinhTrang equals tt.Id_TinhTrang
                        join user in context.aspnet_Users on ttvc.Id_User equals user.UserId
                        join noidi in context.NoiDis on ttvc.IdNoiDi equals noidi.Id_Noidi
                        join noiden in context.NoiDens on ttvc.IdNoiden equals noiden.Id_NoiDen
                        join qg in context.DanhSachQuocGias on noidi.Id_Quocgia equals qg.Id_MaQGia
                        select new
                        {
                            ttvc.Id_TTVC,
                            ttvc.Id_LoHang,
                            user.HoTen,
                            lh.Ten_lo_hang,
                            ttvc.NgayDat,
                            qg.TenQuocGia,
                            noiden.Id_Quocgia,
                            tt.TenTinhTrang
                        };
            int stt = 1;

            foreach (var i in query)
            {
                var query1 = from qg in context.DanhSachQuocGias
                             where qg.Id_MaQGia == i.Id_Quocgia
                             select qg;

                if (stt % 2 == 1)
                    s += "<tr style='height:40px' align='center'>";
                else
                    s += "<tr style='height:40px' bgcolor=#ECE5B6 align='center'>";
                s += " <td >" + stt + "</td>";
                s += "<td> <a href='xoathongtinvanchuyen.aspx?mavc=" + i.Id_TTVC + "'><img  src='../images/delete.gif' border='0'></a></td>";
                s += " <td > <a href='ChiTietLH.aspx?mavc=" + i.Id_TTVC + "'>" + i.Id_LoHang + "</a></td>";
                s += " <td >" + i.Ten_lo_hang + "</td>";
                s += "<td >" + i.HoTen + "</td>";
                s += " <td >" + i.TenQuocGia + "</td>";
                foreach (var j in query1)
                    s += "<td >" + j.TenQuocGia + "</td>";
                s += " <td ><a href='CapNhatTinhTrang1.aspx?mavc=" + i.Id_TTVC + "'>" + i.TenTinhTrang + "</td>";
                s += " <td >" + i.NgayDat + "</td>";
                s += " <td ><a href='InHoaDon.aspx?mavc=" + i.Id_TTVC + "'>" + "In hoá đơn" + "</td>";
                s += "</tr>";

                stt++;
            }
            dynamic.InnerHtml = s;
        }
    }
}